package io.gitee.tziye.core.fs;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
public class RenaiFile {

    private long id;
    private String module;
    private long businessId;
    private Map<String, Object> metadata = new HashMap<>();
    private int seq;
    private byte[] content;
    private Date createTime;

    public RenaiFile(String module, Map<String, Object> metadata, byte[] content) {
        this.module = module;
        this.metadata = metadata;
        this.content = content;
    }

    public RenaiFile(String module, byte[] content) {
        this.module = module;
        this.content = content;
    }

    public int size() {
        return content == null ? 0 : content.length;
    }

    public RenaiFile copy(byte[] content) {
        RenaiFile newFile = new RenaiFile();
        BeanUtils.copyProperties(this, newFile);
        newFile.setContent(content);
        return newFile;
    }

}
